home *** CD-ROM | disk | FTP | other *** search
- /* UPLIMIT - Limit uploads unless we have room
-
- Version 1.10, created on 10/03/86 at 02:37:21
-
- (C) COPYRIGHT 1986 by System Enhancement Associates; ALL RIGHTS RESERVED
-
- By: Thom Henderson
-
- Description:
- This program changes the privilege level of the Fido Upload
- command based on the amount of room left on the upload disk.
-
- Instructions:
- Run this program with a statement of the form:
-
- uplimit [<drive>] <limit>
-
- The <drive> is given in standard DOS notation of A:, B:, etc.
- if no drive is specified, then the current drive is used.
-
- The <limit> is the threshold value. If the disk in question has
- that much room or more, then uploads will be permitted. If it
- has less than that amount of available room, then uploads will
- be restricted.
-
- A <limit> may be specified in any of the following ways:
-
- 1234 1234 bytes.
- 1234K 1234 times 1024 bytes.
- 1234M 1234 times 1024 times 1024 bytes.
-
- As distributed, this program will restrict uploads by making it
- a privileged command, and enable uploads by making it a normal
- command.
-
- SPECIAL NOTES:
- This program is the copyrighted property of System Enhancement
- Associates. You are permitted to copy and distribute it,
- subject to the following conditions:
-
- 1) It must be distributed in its original, unaltered form.
-
- 2) It must be distributed as a complete set of all files.
-
- 3) You may NOT charge in any way for such distribution.
-
- You are also permitted to modify it to suit your needs, provided
- only that you do not distribute the modified version.
-
- Language:
- Computer Innovations Optimizing C86
- */
- #include <stdio.h>
-
- /* User privelege levels */
-
- #define TWIT -2 /* jerk */
- #define DISGRACE 0 /* disgraced user */
- #define NORMAL 2 /* normal user */
- #define PRIVEL 4 /* privileged user */
- #define EXTRA 6 /* extra privileges */
- #define SYSOP 10 /* da boss */
-
- struct privs /* priv file entry structure */
- { char menu[20]; /* menu line */
- int level; /* minimum privelege to use */
- } ;
-
- long roomleft(drive) /* find room left on a drive */
- int drive; /* drive; 0=default, 1=A:, etc. */
- {
- struct {int ax,bx,cx,dx,si,di,ds,es;} reg;
- long room, report;
- char *units = " bytes";
-
- reg.ax = 0x3600; /* get disk free space */
- reg.dx = drive;
- sysint21(®,®); /* DOS call */
-
- if(reg.ax==0xffff)
- abort("%c: is an invalid drive",'A'+drive-1);
-
- room = report = (long)reg.bx * (long)reg.cx * (long)reg.ax;
-
- if(report>=1024)
- { report /= 1024;
- units = "K";
- if(report>=1024)
- { report /= 1024;
- units = " meg";
- }
- }
-
- printf("%ld%s free on",report,units);
- if(drive)
- printf(" drive %c:\n",'A'+drive-1);
- else printf(" current drive.\n");
-
- return room;
- }
-
- main(nargs,arg) /* system entry point */
- int nargs; /* number of arguments */
- char *arg[]; /* pointers to arguments */
- {
- FILE *fp, *fopen(); /* priv file, opener */
- long fploc = 0, fseek(); /* prive file pointer, seeker */
- struct privs priv;
- long limit; /* threshold value */
- char mod; /* modifier */
- int drive = 0; /* drive to check */
- int n;
-
- fprintf(stderr,"UpLimit; Version 1.10, created on 10/03/86 at 02:37:21\n");
- fprintf(stderr,"(C) COPYRIGHT 1986 by System Enhancement Associates;");
- fprintf(stderr," ALL RIGHTS RESERVED\n\n");
-
- if(nargs<2)
- usage();
-
- if(arg[1][1]==':')
- { drive = toupper(arg[1][0]) - 'A' + 1;
- arg[1] = arg[2]; /* sloppy technique, I know */
- }
-
- if(!(n=sscanf(arg[1],"%ld%c",&limit,&mod)))
- usage();
- if(n>1) /* fix limit if modifier given */
- { mod = toupper(mod);
- if(mod=='M' || mod=='K')
- limit *= 1024L;
- else usage();
- if(mod=='M')
- limit *= 1024L;
- }
-
- if(!(fp=fopen("FILEPRIV.BBS","rwb")))
- abort("Cannot read/alter FILEPRIV.BBS");
-
- while(fread(&priv,sizeof(priv),1,fp))
- { if(toupper(*priv.menu)=='U')
- { if(roomleft(drive) < limit)
- { printf("Too little room left. Uploads restricted.\n");
- priv.level = PRIVEL;
- }
- else
- { printf("Suffucient room left. Uploads permitted.\n");
- priv.level = NORMAL;
- }
-
- fseek(fp,fploc,0);
- fwrite(&priv,sizeof(priv),1,fp);
- exit(0);
- }
- else fploc = fseek(fp,0L,1);
- }
-
- abort("U)pload command not found");
- }
-
- usage()
- {
- printf("Changes permission level of the Fido U)pload command based\n");
- printf("on space available.\n\n");
-
- printf("Usage: uplimit [<drive>] [<limit>]\n\n");
-
- printf("Where: <drive> is a standard DOS format drive specifier\n");
- printf(" of A:, B:, et cetera. If no drive is specified,\n");
- printf(" then the current drive is tested.\n\n");
-
- printf(" <limit> is the threshold value. If that amount of\n");
- printf(" room is available, then uploads will be permitted.\n");
- printf(" Otherwise, uploads will be restricted.\n\n");
-
- printf("A <limit> may be specified in any of the following ways:\n\n");
-
- printf(" 1234 1234 bytes.\n");
- printf(" 1234K 1234 times 1024 bytes.\n");
- printf(" 1234M 1234 times 1024 times 1024 bytes.\n");
-
- exit(-1);
- }
-